package com.spring.learn.controller;

import com.spring.learn.model.User;
import com.spring.learn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by baiguantao on 2017/5/22.
 */
@Controller
@RequestMapping("/t/")
public class FirstController {
    @Autowired
    UserService userService;
    @RequestMapping("index")
    public String index(ModelMap map){

        return "index";
    }
    @RequestMapping("test")
    public String test(ModelMap map){

        return "test";
    }
    @RequestMapping("main")
    public String main(ModelMap map){

        return "main";
    }
    @RequestMapping("personInfo")
    public String personInfo(ModelMap map){

        return "personInfo";
    }
    @RequestMapping("tologin")
    public String tologin(ModelMap map){
        return "login";
    }
    @RequestMapping("login")
    public String login(ModelMap map,HttpServletRequest request){
        User user=userService.getUserById("1");
        request.getSession().setAttribute("user",user);
        return "redirect:/t/index";
    }
}
